package cn.shit;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Arrays;
import java.util.Scanner;

public class SocketTest {
    public static void main(String[] args) throws IOException {
        // 获取指定域名的IP地址
        InetAddress address = InetAddress.getByName("www.tmooc.cn");
        System.out.println(address.getHostAddress());
        // 获取本机IP地址
        InetAddress localAddress = InetAddress.getLocalHost();
        System.out.println(localAddress);
        System.out.println(localAddress.getHostAddress());
        try (Socket s = new Socket("www.tmooc.cn",
                80);
             Scanner in = new Scanner(s.getInputStream(), "UTF-8")) {
            s.setSoTimeout(3000);
            while (in.hasNextLine()) {
                String line = in.nextLine();
                System.out.println(line);
            }
        }
    }
}
